package kr.bos.Subclasses;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;

import kr.bos.R;
import kr.bos.Framework.BaseActivity;
import kr.bos.Framework.Logger;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;

/**
 * 콘솔에 스트링 출력 - 실패
 * @author baek - bispro@uracle.co.kr
 * @date 2011. 11. 28.
 */
public class ConsolSysout extends BaseActivity{

	public class LogOutputStream extends OutputStream 
	{ 
	        private ByteArrayOutputStream bos = new ByteArrayOutputStream(); 
	        private String name; 
	        public LogOutputStream( String name ) 
	        { 
	                this.name = name; 
	        } 
	        @Override 
	        public void write( int b ) throws IOException 
	        { 
	                if( b == (int)'\n' ) 
	                { 
	                        String s = new String( this.bos.toByteArray() ); 
	                        Log.v( this.name, s ); 
	                        this.bos = new ByteArrayOutputStream(); 
	                } 
	                else 
	                { 
	                        this.bos.write( b ); 
	                } 
	        } 
	} 
	
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.single_text);
		
		String strEng = "Want to show string to Logcat, Console, TextView!!";
		((TextView)findViewById(R.id.textView1)).setText(strEng);
		Logger.v(strEng);
		System.setErr( new PrintStream( new LogOutputStream( "System.err" ) ) ); 
		System.setOut( new PrintStream( new LogOutputStream( "System.out" ) ) ); 
		
		
		String strKor = "Want to show string to 로그캣, 콘솔, 텍스트뷰!!";
		((TextView)findViewById(R.id.textView2)).setText(strKor);
		Logger.v(strKor);
		System.setErr( new PrintStream( new LogOutputStream( "System.err" ) ) ); 
		System.setOut( new PrintStream( new LogOutputStream( "System.err" ) ) );
	}
}

